import modelExtend from 'dva-model-extend';
import { pageModel } from './common';

import { getTestData,addTestData,removeTestData,updateTestData } from '../services/pagetest';

export default modelExtend(pageModel, {
  namespace: 'pagetest',

  effects: {
    *fetch({ payload = {} }, { call, put }) {
      const response = yield call(getTestData, payload);
      yield put({
        type: 'updateState',
        payload: response,
      });
    },
    *add({ payload = {} }, { call, put }) {
      const response = yield call(addTestData, payload);
      yield put({
        type: 'updateState',
        payload: response,
      });
    },
    *delete({ payload },{ call, put }){
      const response = yield call(removeTestData, payload);
      yield put({
        type: 'updateState',
        payload: response,
      });
    },
    *update({ payload },{ call, put }){
      const response = yield call(updateTestData, payload);
      yield put({
        type: 'updateState',
        payload: response,
      });
    },
  },
});
